package com.example.user1.controller;

import com.example.rabbitmq.config.RabbitConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class send {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping(value = "/test")
    public int test() {
        System.out.println("test accesso ok");
        return 1;
    }

    @PostMapping(value = "/send")
    public void sendMsg(@RequestBody String message) {
        System.out.println("开始发送");
        rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE_NAME, null, message);
        System.out.println("发送完成");
//        System.out.println("输入\n 结束发送");
//        while (!message.equals("\n")){
//
//            Scanner in = new Scanner(System.in);
//            message = in.next();
//        }
    }

}
